package ph.com.gs3.formalistics.fragments.workers;

import org.json.JSONException;

import ph.com.gs3.formalistics.communicators.DocumentCommunicatorModule;
import ph.com.gs3.formalistics.model.dao.DocumentsDAO;
import ph.com.gs3.formalistics.model.dao.FormsDAO;
import ph.com.gs3.formalistics.model.valueobjects.application.Document;
import ph.com.gs3.formalistics.model.valueobjects.application.Form;
import ph.com.gs3.formalistics.model.valueobjects.application.FormField.InvalidFormFieldException;
import android.app.Fragment;

public class DocumentWorkerFragment extends Fragment {

	public static final String TAG = DocumentWorkerFragment.class.getSimpleName();

	private String formId;

	private FormsDAO formsDAO;

	private DocumentCommunicatorModule documentCommModule;
	private DocumentsDAO documentsDAO;

	public static DocumentWorkerFragment createInstance(FormsDAO formsDAO,
	        DocumentsDAO documentsDAO, DocumentCommunicatorModule documentCommModule,
	        String formDbId) {

		DocumentWorkerFragment instance = new DocumentWorkerFragment();

		instance.formId = formDbId;

		// set dependencies
		instance.formsDAO = formsDAO;
		instance.documentsDAO = documentsDAO;

		instance.documentCommModule = documentCommModule;

		return instance;

	}

	public Form getForm() throws JSONException, InvalidFormFieldException {

		Form form;

		formsDAO.open();
		form = formsDAO.getForm(formId);
		formsDAO.close();

		return form;

	}

	public Document getDocument(String documentDbId) {

		Document document = null;

		documentsDAO.open();
		// document = documentsDAO
		documentsDAO.close();

		return document;

	}

}
